package com.cedric.yixianpai.game;

import com.cedric.yixianpai.game.interfaces.Card;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 牌组
 */
public class Decks {
    protected List<Card> cards;

    public Decks(Card... dCards) {
        cards = new ArrayList<>();
        cards.addAll(Arrays.asList(dCards));
//        if (dCards.length >= 3 && dCards.length <= 8) {
//            cards = List.of(dCards);
//        } else {
//            throw new IllegalArgumentException("Number of cards must be between 3 and 8 (inclusive)");
//        }
    }

    public List<Card> getCards() {
        return cards;
    }

    public void setCards(List<Card> cards) {
        this.cards = cards;
    }

    public void addCard(Card newCard) {
        if (cards.size() < 8) {
            cards.add(newCard);
        } else {
            throw new IllegalStateException("Cannot add more cards; deck is already full");
        }
    }

    public void showCards() {
        for (Card card : cards) {
            System.out.println(card.getTitle()+"("+card.getLevel()+")");
        }
    }

    /**
     * 从牌组中取牌
     *
     * @param index 索引
     * @return Card
     */
    public Card getCard(int index) {
        return this.cards.get(index);
    }

    public int getLen() {
        return cards.size();
    }

}
